package login_register

import (
	"golang.org/x/crypto/bcrypt"
	"internal/util"
)

func HashPassword(password string) string {
	hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		util.LogSrv.Error("[Encryption] bcrypt hash failed, err= %v", err)
		return ""
	}
	return string(hashedPassword)
}

func CheckPassword(password, hash string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
	if err != nil {
		util.LogSrv.Info("[Encryption] bcrypt hash failed, err= %v", err)
	}
	return err == nil
}
